/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modulo4;

import Modelo.ComunidadUniversitaria;
import Modelo.DAL.ReporteObjetoPerdido_DAO;
import Acceso.Security;
import Modelo.EntregadoA;
import Modelo.ObjetoPerdido;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Rafael
 */
public class preModificarEOP extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        String[] a = {"Administrador", "Director DSI", "Jefe Apoyo Administrativo", "Personal Administrativo","OP"};
       if (!Security.validateSession(request, a)) {
            return mapping.findForward("errorPriv");
        }
        System.out.println("Paso Autenticación");

        preModificarEOPForm formBean = (preModificarEOPForm) form;
        Long id = formBean.getIdObjeto();
        System.out.println("\n\n AQUI PRE " + id);

        EntregadoA EA = ReporteObjetoPerdido_DAO.obtenerEA(id);
        ObjetoPerdido obj = ReporteObjetoPerdido_DAO.obtenerOP(id);

        ComunidadUniversitaria cu = ReporteObjetoPerdido_DAO.obteneDatCU(EA.getCiRecibe());

        formBean.setVoe(EA.getCiRecibe().substring(0, 1));
        formBean.setCi(EA.getCiRecibe().substring(2, EA.getCiRecibe().length()));

        formBean.setNombre1(cu.getNombre1());
        formBean.setNombre2(cu.getNombre2());
        formBean.setApellido1(cu.getApellido1());
        formBean.setApellido2(cu.getApellido2());
        formBean.setOtro("");

        System.out.println("Profesion "+cu.getProfesion());
        
        if (!cu.getProfesion().equals("Estudiante")
                && !cu.getProfesion().equals("Profesor") && !cu.getProfesion().equals("Empleado")) {
            formBean.setClasificacion("Otro");
            formBean.setOtro(cu.getProfesion());
        } else {
            formBean.setClasificacion(cu.getProfesion());
        }
        formBean.setEmail(cu.getEmail());
        formBean.setTelefono(""+cu.getTelefono());
        formBean.setVoeE(EA.getCiEntrega().substring(0,1));
        formBean.setCiE(EA.getCiEntrega().substring(2,EA.getCiEntrega().length()));

        formBean.setDescripcion(obj.getDescripcion());
        formBean.setFechaEncontrado(obj.getStatus());
        formBean.setTipoObjeto(obj.getIdTipoObjeto());
        formBean.setObservaciones(EA.getObservaciones());

        return mapping.findForward(SUCCESS);
    }
}
